package com.example.mp;

import com.example.mp.mapper.UserMapper;
import com.example.mp.pojo.User;
import com.example.mp.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @BelongsProject: MP
 * @BelongsPackage: com.example.mp
 * @Author: wyj
 * @CreateTime: 2024-05-25  00:17
 * @Description:
 * @Version: 1.0
 */
@SpringBootTest
public class MpTestService {

    @Autowired
    private UserService userService;


    @Autowired
    private UserMapper userMapper;

    @Test
    public void testCount() {
        // 测试查询总记录数
        long count = userService.count();
        System.out.println(count);
    }

    @Test
    public void testInsertBatch() {
        //sql ==>  Preparing: INSERT INTO user ( id, name, age ) VALUES ( ?, ?, ? )
        // 批量添加 通过单个添加进行循环操作
        List<User> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setName("wyja" + i);
            user.setAge(20 + i);
            list.add(user);
        }

        boolean flag = userService.saveBatch(list);
        System.out.println(flag);
    }

    @Test
    public void testList() {
        List<User> list = userService.list();
        System.out.println(list);
    }

    @Test
    public void testDelLogin() {
        // 逻辑删除  默认 0 未删除  1 已删除
        int i = userMapper.deleteBatchIds(Arrays.asList(1, 2, 3, 4));
        System.out.println(i);
        userMapper.selectList(null).forEach(System.out::println);
    }
}
